package org.rsbot.bot;

import org.rsbot.client.Callback;
import org.rsbot.client.Render;
import org.rsbot.client.RenderData;
import org.rsbot.event.events.CharacterMovedEvent;
import org.rsbot.event.events.MessageEvent;
import org.rsbot.event.events.ServerMessageEvent;
import org.rsbot.script.Calculations;
import org.rsbot.script.Methods;

public class CallbackImpl implements Callback {

    private final Bot bot;

    public CallbackImpl(Bot bot) {
        this.bot = bot;
    }

    public Bot getBot() {
        return bot;
    }

    @SuppressWarnings("deprecation")
    public void notifyMessage(final int id, final String sender, final String msg) {
        MessageEvent m = new MessageEvent(sender, id, msg);
        bot.getEventManager().dispatchEvent(m);
        if (id == MessageEvent.MESSAGE_SERVER || id == MessageEvent.MESSAGE_ACTION) {
            ServerMessageEvent e = new ServerMessageEvent(msg);
            bot.getEventManager().dispatchEvent(e);
        }
    }

    public void rsCharacterMoved(final org.rsbot.client.RSCharacter c, final int i) {
        CharacterMovedEvent e = new CharacterMovedEvent(bot.getMethods(), c, i);
        bot.getEventManager().dispatchEvent(e);
    }

    public void updateRenderInfo(final Render r, final RenderData rd) {
        Methods ctx = bot.getMethods();
        if (ctx != null) {
            Calculations.updateRenderInfo(r, rd);
        }
    }
}
